
package com.sgcc.ln.pmos.common.view;

import android.content.Context;
import android.widget.TextView;

import com.github.mikephil.charting.data.CandleEntry;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.utils.MPPointF;
import com.sgcc.pmos.nativesdk.R;
import com.sgcc.ln.pmos.common.utils.BigDecimalUtils;

public class LineMarkerView extends com.github.mikephil.charting.components.MarkerView {

    private final TextView tvContent;
    private final TextView tvContent1;
    private int type = 0;

    public LineMarkerView(Context context) {
        super(context, R.layout.custom_marker_view);

        tvContent = findViewById(R.id.tvContent);
        tvContent1 = findViewById(R.id.tvContent1);
    }

    public LineMarkerView(Context context, int type) {
        super(context, R.layout.custom_marker_view);
        tvContent = findViewById(R.id.tvContent);
        tvContent1 = findViewById(R.id.tvContent1);
        this.type = type;
    }


    @Override
    public void refreshContent(Entry e, Highlight highlight) {

        tvContent.setText(String.format("时段%s", (int) e.getX() + 1));
        String number;
        if (e instanceof CandleEntry) {
            CandleEntry ce = (CandleEntry) e;
            number = ce.getY() + "";
        } else {
            number = e.getY() + "";
        }
        tvContent1.setText(String.format(type == 0 ? "%s元/度 " : type == 1 ? "%s元/MWh " : "%s", number));

        super.refreshContent(e, highlight);
    }

    @Override
    public MPPointF getOffset() {
        return new MPPointF(-(getWidth() / 2), -getHeight());
    }
}
